package org.rsbot.script.webwalking;

import java.awt.BorderLayout;
import java.net.URL;

import javax.swing.JFrame;
import javax.swing.JScrollPane;

/**
 * 
 * @author WebWalker
 */
public class MapGraph {

	public String fileName = "rsmap.jpg";
	public URL iURL = MapGraph.class.getResource("resources/" + fileName);

	private final double DimensionW = 3713;
	private final double DimensionH = 3329;

	private final double OriginX = 2047.5;
	private final double OriginY = 2494.5;

	private final double NorthX = 2047.5;
	private final double NorthY = 4159.0;

	private final double EastX = 3904.0;
	private final double EastY = 2494.5;

	PicInfo pi;
	JFrame j;
	MapLabel p;

	public MapGraph() {
		try {
			pi = new PicInfo(new XY(OriginX, OriginY), new XY(NorthX, NorthY),
					new XY(EastX, EastY), new XY(DimensionW, DimensionH),
					iURL.toString());
			j = new JFrame("Map graph - Please wait until image is loaded!");
			p = new MapLabel(iURL);
			JScrollPane pane = new JScrollPane();
			pane.getViewport().add(p);
			j.add(pane, BorderLayout.CENTER);
			j.setSize(500 + 12, 500 + 31);
			j.setResizable(true);
			j.setVisible(true);
			p.setIcon();
			while (j.isVisible()) {
				try {
					if (p.getMousePosition() != null
							&& p.getMousePosition().x > 0
							&& p.getMousePosition().y > 0) {
						j.setTitle("Made by WebWalker - Tile = new RSTile("
								+ (int) p.getHoveringTile(pi).x + ", "
								+ (int) p.getHoveringTile(pi).y + ")"
								+ " Click a tile to copy to clipboard");
					} else
						j.setTitle("Made by WebWalker - Tile = new RSTile(0,0)");
				} catch (Exception e) {
					j.setTitle("Made by WebWalker - Tile = new RSTile(0,0)");
				}
				Thread.sleep(50);
			}
			j.dispose();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static class XY {
		public final double x;
		public final double y;

		public XY(double x, double y) {
			this.x = x;
			this.y = y;
		}
	}

	public class PicInfo {

		public final XY originTile;
		public final XY northTile;
		public final XY eastTile;
		public final XY dimensions;
		public final String pictureURL;

		public PicInfo(XY originTile, XY northTile, XY eastTile, XY dimensions,
				String iURL) {
			this.originTile = originTile;
			this.northTile = northTile;
			this.eastTile = eastTile;
			this.dimensions = dimensions;
			this.pictureURL = iURL;
		}
	}

	public static void main(String args[]) {
		new MapGraph();
	}
}